package com.zac.coroutine.algorithm.leetcode.tree;

/**
 * author zac
 * date 2024/11/20
 * 给你一个二叉树的根节点 root ， 检查它是否轴对称。
 */
public class TreeTest2 {


    public boolean isSymmetric(TreeNode root) {
        if (root == null) return true;
        if (root.left == null && root.right == null)return true;
        if (root.left == null || root.right == null)return false;
        if (root.left.val == root.right.val) {
            return isS(root.left, root.right);
        } else return false;
    }

    public boolean isS(TreeNode inLeft, TreeNode inRight) {
        if (inLeft == null && inRight == null) {
            return true;
        } else if (inLeft == null || inRight == null) {
            return false;
        }

        if (inLeft.val == inRight.val) {
            return (isS(inLeft.left, inRight.right) && isS(inLeft.right, inRight.left));
        }
        return false;
    }

}
